package com.ok.cartoon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ok.cartoon.domain.po.OkArea;
import com.ok.cartoon.domain.po.OkCartoonCategory;
import com.ok.cartoon.service.IOkCartoonCategoryService;
import com.ok.common.domain.po.Pages;
import com.ok.common.domain.po.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 漫画分类 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-04-28
 */
@Api(tags = "漫画分类相关接口")
@RestController
@RequestMapping("/cartoonCategory")
@RequiredArgsConstructor
public class OkCartoonCategoryController {

    private final IOkCartoonCategoryService okCartoonCategoryService;

    @ApiOperation(value = "添加分类")
    @PostMapping("/add")
    public Result add(@RequestParam String name){
        OkCartoonCategory category = new OkCartoonCategory();
        category.setName(name);
        okCartoonCategoryService.save(category);

        return Result.success("添加成功");
    }

    @ApiOperation(value = "删除分类")
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        okCartoonCategoryService.removeWith(id);
        return Result.success("删除成功");
    }

    @ApiOperation(value = "修改分类")
    @PutMapping("/update")
    public Result update(@RequestBody OkCartoonCategory okCartoonCategory){
        okCartoonCategoryService.updateById(okCartoonCategory);
        return Result.success("修改成功");
    }

    @ApiOperation("分页查询漫画分类")
    @GetMapping("/page")
    public Result page(@RequestParam Integer pageNo,@RequestParam Integer pageSize){
        Page<OkCartoonCategory> pageInfo = new Page<>(pageNo, pageSize);
        Page<OkCartoonCategory> page = okCartoonCategoryService.page(pageInfo);
        return Result.success(page);
    }

    @ApiOperation(value = "查询所有分类")
    @GetMapping("/list")
    public Result list(){
        List<OkCartoonCategory> list = okCartoonCategoryService.list();
        return Result.success(list);
    }
}
